package com.task.controller;


import com.task.bean.Task;
import com.task.service.ITaskService;
import com.task.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuzhe
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private ITaskService taskService;

    @GetMapping("/list")
    public ResultVo list(int pageNum, int pageSize, int teaId) {
        return ResultVo.success(taskService.list(pageNum, pageSize, teaId));
    }

    @PostMapping("/publish")
    public ResultVo publish(@RequestBody Task task) throws ParseException {
        task.setCreateTime(new Date());
        return ResultVo.success(taskService.save(task));
    }

    @GetMapping("/queryAllByStuId")
    public ResultVo queryAllByStuId(int stuId) {
        return ResultVo.success(taskService.queryAllByStuId(stuId));
    }

    @PutMapping("/updateStatus")
    public ResultVo updateStatus(int id) {
        Task task = taskService.getById(id);
        task.setStatus(1);
        return ResultVo.success(taskService.updateById(task));
    }

    @GetMapping("/getTask")
    public ResultVo getTask(int taskId) {
        return ResultVo.success(taskService.getById(taskId));
    }

    @GetMapping("/getTaskItem")
    public ResultVo getTaskItem(int teaId, int taskId) {
        return ResultVo.success(taskService.getTaskItem(teaId,taskId));
    }
}

